﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ERPStore.Exporter.EventConsumers
{
	public class BanishProductEventConsumer : EventBrokR.IConsumer<ERPStore.Events.GlobalEvent>
	{
		public BanishProductEventConsumer(Services.ExporterService exporterService)
		{
			this.ExporterService = exporterService;
		}

		protected Services.ExporterService ExporterService { get; private set; }

		public void Handle(ERPStore.Events.GlobalEvent @event)
		{
			if (@event.EventName != "BanishProduct")
			{
				return;
			}

			int productId = @event.Source.ProductId;
			string leadSourceId = @event.Source.LeadSourceId;

			var banishedProduct = ExporterService.CreateBanishedProduct();
			banishedProduct.ProductId = productId;
			banishedProduct.SourceId = leadSourceId;

			ExporterService.SaveBanishedProduct(banishedProduct);
		}
	}
}
